/*
 * Copyright (c) 2010-2011 Plugger Antonio Begue Ponce. All Rights Reserved.
 *
 * This file is part of Plugger Framework.
 *
 *  Plugger Framework is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License version 3 as published by
 *  the Free Software Foundation.
 *
 *  Plugger Framework is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Plugger Framework.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.plugger.infrastructure.repositorybase;

import java.io.Serializable;
import java.util.List;

/**
 * Represent the Unit Of Work.<BR/>
 * The workspace encapsulate the O/R Unit Of Work.<BR/>
 * Implements the CRUD functions.
 *
 * @author Antonio Begue
 * @version $Revision: 1.0 $
 *
 * @see     RepositoryBase
 * @see     IRepository
 */
public interface IWorkspace {
    /**
     * Add an entity to the Unit Of Work and update any CRUD manipulation.
     * @param o The entity added.
     */
    void makePersistent(Object o);

    /**
     * Add a detached entity to the Unit Of Work.
     * @param o The entity added.
     */
    void lock(Object o);

    /**
     * Commit all changes of all entities in the Unit Of Work.
     */
    void persistAll();

    /**
     * Mark an entity as deleted, but you need to persistAll to actually delete it from persistence.
     * @param o The entity deleted.
     */
    void delete(Object o);

    /**
     * Removes all entities from the Unit Of Work.
     */
    void clean();

    /**
     * clean and close the workspace.
     */
    void close();

    /**
     * Disconnect the workspace from the database.
     */
    void disconnect();

    /**
     * Reconnect the workspace to the database
     */
    void reconnect();

    /**
     * Retrieve an entity from persistence using the entity key.
     *
     * @param <T> The Type to retrieve.
     * @param typeToGet The Class<T> to retrieve.
     * @param idValue the entity key.
     * @return an entity of type T.
     */
    <T> T getById(Class<T> typeToGet, Serializable idValue);

    /**
     * Retrieve all the entities of type T from persistence.
     *
     * @param <T> The Type to retrieve.
     * @param typeOfResult The Class<T> to retrieve.
     * @return an entity list of type T.
     */
    <T> List<T> getAll(Class<T> typeOfResult);

    /**
     * Beguin a database transaction.
     */
    void beginTransaction();

    /**
     * Commit a database transaction.
     */
    void commit();

    /**
     * Rollback a database transaction.
     */
    void rollback();
}
